from PyCmpltrtok.common import sep

sep('idx and key')
print('My name is {name}, I am {age}, and my salary is {}. {}'.format(14000.00, 'Good luck!', age=38, name='Peter '
                                                                                                           'Payne'))
sep('idx')
print('{1} is a {0}'.format('Fruit', 'Apple'))
print('{} is a {}'.format('Apple', 'Fruit'))

sep('Access element by idx')
a = ['foo', 'bar', 'baz']
print('{0[0]}, {0[2]}'.format(a))

sep('Access element by [key]')
d = {'key1': 'foo苦差', 'key2': 'bar乐差', 'key3': 1234}
print('{0[key1]}'.format(d))

sep('Access attribute by .key')
z = 3 + 5j
print('real = {z.real} + {z.imag}i'.format(z=z))
print('real = {0.real} + {0.imag}i'.format(z))

sep('reprs')
# help(repr)
print(repr(d))
print(repr(a))
i1 = 123
print(repr(i1))
str1 = 'abcd'
print(repr(str1))

sep('ascii')
# help(ascii)
print(ascii(d))

sep('!s !r !a')
print('{0[key1]!s} {0[key1]!r} {0[key1]!a}'.format(d))
print('{0[key3]!s:10s} {0[key3]!r} {0[key3]!a}'.format(d))

sep('More exercise')
xdict = {
    'xlist': [3.1415926, 1997, 2008]
}
print('Pi = {0[xlist][0]:8.4f}; Hongkong comes back in {0[xlist][1]:06d}; Beijing Olympic helds in {0[xlist][2]: 6d}'.format(xdict))
# print('Pi = {0.xlist[0]:8.4f}'.format(xdict))  # AttributeError: 'dict' object has no attribute 'xlist'
